<?php
class Admin_PagesController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$model=new Admin_Model_page();
		$this->view->pages=$model->lists();
	}
	public function viewAction()
	{
		$id = $this->getRequest()->getParam('id');
		$model=new Admin_Model_page();
		$data=$model->getPage($id);
		$this->view->title=$data->title;
		$this->view->content=$data->content;
	}
	public function createAction()
	{
		$form=new Admin_Form_Page();
		$form->init();
		$form->setMethod('post');
		if($this->getRequest()->isPost())
			{
				if($form->isValid($_POST))
				{
					$title=$form->getValue('title');
					$position=$form->getValue('position');
					$content=$form->getValue('content');
					$status=$form->getValue('status');
					$data=new Admin_Model_page();
					$data->NewPage($position, $title, $content, $status);
					$this->_redirect('admin/pages/index');
				}
			}
		$this->view->form=$form;
		
	}
	public function editAction()
	{
		$form=new Admin_Form_Page();
		$form->init();
		$form->setMethod('post');
	if($this->getRequest()->isPost())
			{
				if($form->isValid($_POST))
				{
					$id=$form->getValue('pageid');
					$title=$form->getValue('title');
					$position=$form->getValue('position');
					$content=$form->getValue('content');
					$status=$form->getValue('status');
					$data=new Admin_Model_page();
					$data->updatePage($id, $title, $position, $content, $status);
					$this->_redirect('admin/pages/index');
				}
			}
		else {
		$id = $this->getRequest()->getParam('id');
		$model=new Admin_Model_page();
		$data=$model->getPage($id);
		$form=new Admin_Form_Page();
		$form->populate($data->toArray());
		$this->view->form=$form;
		}
	}
	public function deleteAction()
	{
		$id = $this->getRequest()->getParam('id');
		$model=new Admin_Model_page();
		$model->deletePage($id);
		$this->_redirect('admin/pages/index');
	}
}